package com.laowang.project.system.mapper;

import java.util.Date;
import java.util.List;

import com.laowang.common.utils.StringUtils;
import com.laowang.project.system.domain.SysDictType;
import tk.mybatis.mapper.additional.idlist.DeleteByIdListMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

/**
 * 字典表 数据层
 * 
 * @author laowang
 */
public interface SysDictTypeMapper extends Mapper<SysDictType>, DeleteByIdListMapper<SysDictType, Long>
{
    /**
     * 根据条件分页查询字典类型
     * 
     * @param dictType 字典类型信息
     * @return 字典类型集合信息
     */
    default List<SysDictType> selectDictTypeList(SysDictType dictType) {
        Example example = new Example(SysDictType.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(dictType.getDictName())) {
            criteria.andLike("dictName", "%" + dictType.getDictName() + "%");
        }
        if (StringUtils.isNotEmpty(dictType.getStatus())) {
            criteria.andEqualTo("status", dictType.getStatus());
        }
        if (StringUtils.isNotEmpty(dictType.getDictType())) {
            criteria.andLike("dictType", "%" + dictType.getDictType() + "%");
        }
        if (StringUtils.isNotEmpty(dictType.getBeginTime())) {
            criteria.andCondition("date_format(create_time, '%y%m%d') >= date_format('" + dictType.getBeginTime() + "', '%y%m%d')");
        }
        if (StringUtils.isNotEmpty(dictType.getEndTime())) {
            criteria.andCondition("date_format(create_time, '%y%m%d') <= date_format('" + dictType.getEndTime() + "', '%y%m%d')");
        }
        return selectByExample(example);
    }

    /**
     * 根据字典类型查询信息
     * 
     * @param dictType 字典类型
     * @return 字典类型
     */
    default SysDictType selectDictTypeByType(String dictType) {
        Example example = new Example(SysDictType.class);
        example.createCriteria().andEqualTo("dictType", dictType);
        return selectOneByExample(example);
    }

    /**
     * 新增字典类型信息
     * 
     * @param dictType 字典类型信息
     * @return 结果
     */
    default int insertDictType(SysDictType dictType) {
        dictType.setCreateTime(new Date());
        return insertSelective(dictType);
    }
}
